package ace.module.oss.core.impl.manager.impl;

import ace.cmp.core.constants.CoreConstant;
import ace.cmp.data.spring.data.jdbc.querydsl.rsql.core.manager.spring.AbstractSpringDtoManager;
import ace.cmp.i18n.api.MessageSourceAssertService;
import ace.module.oss.api.model.dto.OssApplicationSupplierDto;
import ace.module.oss.core.impl.dao.entity.OssApplicationSupplier;
import ace.module.oss.core.impl.dao.repository.OssApplicationSupplierRepository;
import ace.module.oss.core.impl.manager.OssApplicationSupplierManager;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Oss应用供应商 spring data jdbc querydsl rsql manager implement.
 *
 * @author Caspar
 */
@Slf4j
@AllArgsConstructor
@Component
public class OssApplicationSupplierManagerImpl
    extends AbstractSpringDtoManager<OssApplicationSupplier, Long,  OssApplicationSupplierDto>
    implements OssApplicationSupplierManager {

  private final OssApplicationSupplierRepository ossApplicationSupplierRepository;
  private final MessageSourceAssertService assertService;

  @Override
  public OssApplicationSupplier getAndCheckByOssAppId(Long ossAppId) {
    OssApplicationSupplier ossApplicationSupplier =
        this.ossApplicationSupplierRepository.getByOssAppIdAndDeleteFlagIs(
            ossAppId, CoreConstant.DELETE_FLAG_NOT);
    assertService.isNull(
        ossApplicationSupplier,
        OssApplicationSupplier.class.getName() + ".error-is-null",
        "应用供应商配置不存在");
    assertService.isFalse(
        ossApplicationSupplier.getDeleteFlag().equals(CoreConstant.DELETE_FLAG_NOT),
        "account.password.error-is-null",
        "应用供应商配置不存在");
    return ossApplicationSupplier;
  }
}
